// Created from GenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Reflection;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.Generated.AbstractMessage;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using TX = System.String;
using FT = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class CCI_I22 : AbstractMessage
    {
		/// Constructor
		public CCI_I22() : base()
        {
			if (MSH != null) {
                MSH.MessageType = new MSG() { MessageCode = "CCI", TriggerEvent = "I22" };
			}
        }

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("SFT",2)]
  	    [HL7Field(HL7Version.v27, 2, HL7Repeat.True, HL7Required.False,"SFT")]
	    public SFT[] SFT {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("UAC",3)]
  	    [HL7Field(HL7Version.v27, 3, HL7Repeat.False, HL7Required.False,"UAC")]
	    public UAC UAC {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("MSA",4)]
  	    [HL7Field(HL7Version.v27, 4, HL7Repeat.False, HL7Required.True,"MSA")]
	    public MSA MSA {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("ERR",5)]
  	    [HL7Field(HL7Version.v27, 5, HL7Repeat.True, HL7Required.False,"ERR")]
	    public ERR[] ERR {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("PID",6)]
  	    [HL7Field(HL7Version.v27, 6, HL7Repeat.False, HL7Required.True,"PID")]
	    public PID PID {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("PD1",7)]
  	    [HL7Field(HL7Version.v27, 7, HL7Repeat.False, HL7Required.False,"PD1")]
	    public PD1 PD1 {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("NK1",8)]
  	    [HL7Field(HL7Version.v27, 8, HL7Repeat.True, HL7Required.False,"NK1")]
	    public NK1[] NK1 {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("INSURANCE",9)]
  	    [HL7Field(HL7Version.v27, 9, HL7Repeat.True, HL7Required.False,"INSURANCE_CCI_I22")]
	    public INSURANCE_CCI_I22[] INSURANCE {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("APPOINTMENT_HISTORY",14)]
  	    [HL7Field(HL7Version.v27, 14, HL7Repeat.True, HL7Required.False,"APPOINTMENT_HISTORY_CCI_I22")]
	    public APPOINTMENT_HISTORY_CCI_I22[] APPOINTMENT_HISTORY {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("CLINICAL_HISTORY",34)]
  	    [HL7Field(HL7Version.v27, 34, HL7Repeat.True, HL7Required.False,"CLINICAL_HISTORY_CCI_I22")]
	    public CLINICAL_HISTORY_CCI_I22[] CLINICAL_HISTORY {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("PATIENT_VISITS",78)]
  	    [HL7Field(HL7Version.v27, 78, HL7Repeat.True, HL7Required.True,"PATIENT_VISITS_CCI_I22")]
	    public PATIENT_VISITS_CCI_I22[] PATIENT_VISITS {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("MEDICATION_HISTORY",82)]
  	    [HL7Field(HL7Version.v27, 82, HL7Repeat.True, HL7Required.False,"MEDICATION_HISTORY_CCI_I22")]
	    public MEDICATION_HISTORY_CCI_I22[] MEDICATION_HISTORY {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("PROBLEM",103)]
  	    [HL7Field(HL7Version.v27, 103, HL7Repeat.True, HL7Required.False,"PROBLEM_CCI_I22")]
	    public PROBLEM_CCI_I22[] PROBLEM {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("GOAL",118)]
  	    [HL7Field(HL7Version.v27, 118, HL7Repeat.True, HL7Required.False,"GOAL_CCI_I22")]
	    public GOAL_CCI_I22[] GOAL {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("PATHWAY",133)]
  	    [HL7Field(HL7Version.v27, 133, HL7Repeat.True, HL7Required.False,"PATHWAY_CCI_I22")]
	    public PATHWAY_CCI_I22[] PATHWAY {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("REL",148)]
  	    [HL7Field(HL7Version.v27, 148, HL7Repeat.True, HL7Required.False,"REL")]
	    public REL[] REL {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override Stack<string> ConsumeTextSegments(Stack<string> availableData, HL7ParserOptions options) {

				if (HL7Version.v27 == options.Version) {
		 SFT = PopSegmentParseAndCheckRequiredArray<SFT>(availableData, options, "SFT");
		 UAC = PopSegmentParseAndCheckRequired<UAC>(availableData, options, "UAC");
		 MSA = PopSegmentParseAndCheckRequired<MSA>(availableData, options, "MSA");
		 ERR = PopSegmentParseAndCheckRequiredArray<ERR>(availableData, options, "ERR");
		 PID = PopSegmentParseAndCheckRequired<PID>(availableData, options, "PID");
		 PD1 = PopSegmentParseAndCheckRequired<PD1>(availableData, options, "PD1");
		 NK1 = PopSegmentParseAndCheckRequiredArray<NK1>(availableData, options, "NK1");
		 INSURANCE = ProcessGroupArray<INSURANCE_CCI_I22>(availableData, options, "INSURANCE");
		 APPOINTMENT_HISTORY = ProcessGroupArray<APPOINTMENT_HISTORY_CCI_I22>(availableData, options, "APPOINTMENT_HISTORY");
		 CLINICAL_HISTORY = ProcessGroupArray<CLINICAL_HISTORY_CCI_I22>(availableData, options, "CLINICAL_HISTORY");
		 PATIENT_VISITS = ProcessGroupArray<PATIENT_VISITS_CCI_I22>(availableData, options, "PATIENT_VISITS");
		 MEDICATION_HISTORY = ProcessGroupArray<MEDICATION_HISTORY_CCI_I22>(availableData, options, "MEDICATION_HISTORY");
		 PROBLEM = ProcessGroupArray<PROBLEM_CCI_I22>(availableData, options, "PROBLEM");
		 GOAL = ProcessGroupArray<GOAL_CCI_I22>(availableData, options, "GOAL");
		 PATHWAY = ProcessGroupArray<PATHWAY_CCI_I22>(availableData, options, "PATHWAY");
		 REL = PopSegmentParseAndCheckRequiredArray<REL>(availableData, options, "REL");
		}
			if (availableData != null && availableData.Count > 0) {
				ConsumeZSegmentsFromText(availableData, options);
			}
            return availableData;
        
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "CCI_I22";
			}
        }

        static CCI_I22() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(CCI_I22));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
			if (MSH != null) {
				segmentData.Add(MSH.GetER7(options));
			}
			if (SFT != null && SFT.Length > 0) {
				for (int i = 0; i < SFT.Length; i++) {
					segmentData.Add(SFT[i].GetER7(options));
				}
			}
			if (UAC != null) {
				segmentData.Add(UAC.GetER7(options));
			}
			if (MSA != null) {
				segmentData.Add(MSA.GetER7(options));
			}
			if (ERR != null && ERR.Length > 0) {
				for (int i = 0; i < ERR.Length; i++) {
					segmentData.Add(ERR[i].GetER7(options));
				}
			}
			if (PID != null) {
				segmentData.Add(PID.GetER7(options));
			}
			if (PD1 != null) {
				segmentData.Add(PD1.GetER7(options));
			}
			if (NK1 != null && NK1.Length > 0) {
				for (int i = 0; i < NK1.Length; i++) {
					segmentData.Add(NK1[i].GetER7(options));
				}
			}
			if (INSURANCE != null && INSURANCE.Length > 0) {
				for (int i = 0; i < INSURANCE.Length; i++) {
					segmentData.Add(INSURANCE[i].GetER7(options));
				}
			}
			if (APPOINTMENT_HISTORY != null && APPOINTMENT_HISTORY.Length > 0) {
				for (int i = 0; i < APPOINTMENT_HISTORY.Length; i++) {
					segmentData.Add(APPOINTMENT_HISTORY[i].GetER7(options));
				}
			}
			if (CLINICAL_HISTORY != null && CLINICAL_HISTORY.Length > 0) {
				for (int i = 0; i < CLINICAL_HISTORY.Length; i++) {
					segmentData.Add(CLINICAL_HISTORY[i].GetER7(options));
				}
			}
			if (PATIENT_VISITS != null && PATIENT_VISITS.Length > 0) {
				for (int i = 0; i < PATIENT_VISITS.Length; i++) {
					segmentData.Add(PATIENT_VISITS[i].GetER7(options));
				}
			}
			if (MEDICATION_HISTORY != null && MEDICATION_HISTORY.Length > 0) {
				for (int i = 0; i < MEDICATION_HISTORY.Length; i++) {
					segmentData.Add(MEDICATION_HISTORY[i].GetER7(options));
				}
			}
			if (PROBLEM != null && PROBLEM.Length > 0) {
				for (int i = 0; i < PROBLEM.Length; i++) {
					segmentData.Add(PROBLEM[i].GetER7(options));
				}
			}
			if (GOAL != null && GOAL.Length > 0) {
				for (int i = 0; i < GOAL.Length; i++) {
					segmentData.Add(GOAL[i].GetER7(options));
				}
			}
			if (PATHWAY != null && PATHWAY.Length > 0) {
				for (int i = 0; i < PATHWAY.Length; i++) {
					segmentData.Add(PATHWAY[i].GetER7(options));
				}
			}
			if (REL != null && REL.Length > 0) {
				for (int i = 0; i < REL.Length; i++) {
					segmentData.Add(REL[i].GetER7(options));
				}
			}
           segmentData.AddRange(GetZSegmentsER7(options));
		   return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }


    }
}

